<template>
	<view class="container">
		
		<view class="setting-list">
			<view class="setting-item">
				<view class="setting-item-label">
					租期1个月及以内，到期前
				</view>
				<view class="setting-item-value">
					<u-input  v-model="form.one_month" inputAlign="right" border="none">
						<template slot="suffix">天提醒</template>
					</u-input>
				</view>
			</view>
			
			<view class="setting-item">
				<view class="setting-item-label">
					租期6个月及以内，到期前
				</view>
				<view class="setting-item-value">
					<u-input  v-model="form.six_month" inputAlign="right" border="none">
						<template slot="suffix">天提醒</template>
					</u-input>
				</view>
			</view>
			
			<view class="setting-item">
				<view class="setting-item-label">
					租期6个月以上，到期前
				</view>
				<view class="setting-item-value">
					<u-input  v-model="form.gt_six_month" inputAlign="right" border="none">
						<template slot="suffix">天提醒</template>
					</u-input>
				</view>
			</view>
			
			<view class="setting-item">
				<view class="setting-item-label">
					自动续租
				</view>
				<view class="setting-item-value">
					<u-switch slot="right" v-model="form.auto_pay" activeColor="#FE4F04" size="18" activeValue="1" inactiveValue="0"></u-switch>
				</view>
			</view>
			
			<view class="setting-item">
				<view class="setting-item-label">
					到期前
				</view>
				<view class="setting-item-value">
					<u-input  v-model="form.ahead_auto_pay" inputAlign="right" border="none">
						<template slot="suffix">天续租</template>
					</u-input>
				</view>
			</view>
		</view>
		
		
		<view class="form-bottom-opt">
			<u-button @click="submit" :custom-style="submitBtnStyle">提交</u-button>
		</view>
	</view>
</template>

<script>
	import { getUserConfigContract, setUserConfigContract } from '@/api/part2.js'
	
	export default {
		data() {
			return {
				form: {
					one_month:'',//租期1个月及以内，到期前
					six_month:'',//租期6个月及以内，到期前
					gt_six_month:'',//租期6个月以上，到期前
					auto_pay:'0',//自动续租
					ahead_auto_pay:'', //到期前
				},
				submitBtnStyle: {
					background: "#FE4F04",
					boShadow: "0rpx 4rpx 8rpx 0rpx rgba(254,79,4,0.5)",
					borderRadius: "44rpx",
					fontSize: "30rpx",
					color: "#FFFFFF",
					height: "88rpx",
				},
			}
		},
		onLoad() {
			this.getUserConfigContract()
		},
		methods:{
			getUserConfigContract(){
				getUserConfigContract().then(res=>{
					console.log('合同设置：',res)
					let data = res.data.data
					data.forEach(d=>{
						console.log(d)
						this.form[d.field] = d.value || this.form[d.field]
					})
				})
			},
			submit(){
				setUserConfigContract(this.form).then(res=>{
					uni.showToast({
						icon:'none',
						title:res.msg
					})
					setTimeout(()=>{
						uni.navigateBack()
					},800)
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	view {
		box-sizing: border-box;
	}
	.container {
		padding: 12rpx 0;
	}
	.setting-list {
		.setting-item {
			width: 750rpx;
			height: 112rpx;
			background: #FFFFFF;
			margin-bottom: 2rpx;
			padding: 36rpx 40rpx;
			
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;
			
			.setting-item-label {
				white-space: nowrap;
				color: #666666;
			}
			
			.setting-item-value {
				font-size: 28rpx;
				color: #000000;
			}
		}
	}
	.tips {
		margin-top: 28rpx;
		padding: 20rpx 48rpx;
		font-size: 26rpx;
		color: #2A0C00;
		font-weight: 700;
	}
	.tips-input {
		background-color: #fff;
		// padding: 18rpx 22rpx;
	}
	/deep/.u-textarea {
		padding: 36rpx 40rpx !important;
		font-size: 28rpx !important;
	}
	.form-bottom-opt {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 1000;
		/* 关键样式 - 使用 constant 和 env 兼容不同设备 */
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
		/* 其他样式按需添加 */
		background-color: #F5F6FA;
		padding: 20rpx 40rpx;
	}
	
</style>